{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "import google.generativeai as genai\n",
        "import os\n",
        "import json\n",
        "import re\n",
        "from pathlib import Path\n",
        "from typing import List, Dict"
      ],
      "metadata": {
        "id": "nIiCCq4Nvnq7"
      },
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "class TinyDev:\n",
        "    \"\"\"\n",
        "    TinyDev: A lightweight AI code generator inspired by smol-dev\n",
        "    Uses Gemini API to generate complete applications from simple prompts\n",
        "    Follows the proven three-phase workflow: Plan → Files → Code\n",
        "    \"\"\"\n",
        "\n",
        "    def __init__(self, api_key: str, model: str = \"gemini-1.5-flash\"):\n",
        "        genai.configure(api_key=api_key)\n",
        "        self.model = genai.GenerativeModel(model)\n",
        "        self.generation_config = {\n",
        "            'temperature': 0.1,\n",
        "            'top_p': 0.8,\n",
        "            'max_output_tokens': 8192,\n",
        "        }\n",
        "\n",
        "    def plan(self, prompt: str) -> str:\n",
        "        \"\"\"\n",
        "        Phase 1: Generate project plan and shared dependencies\n",
        "        Creates the foundation for consistent code generation\n",
        "        \"\"\"\n",
        "        planning_prompt = f\"\"\"You are an AI developer who is trying to write a program that will generate code for the user based on their intent.\n",
        "\n",
        "the program you are writing is based on the following description:\n",
        "{prompt}\n",
        "\n",
        "the files we write will be generated by a python script. the goal is for us to all work together to write a program that will write the code for the user.\n",
        "\n",
        "since we are working together, we need to understand what our shared dependencies are. this includes:\n",
        "- import statements we all need to use\n",
        "- variable names that are shared between files\n",
        "- functions that are called from one file to another\n",
        "- any other shared state\n",
        "\n",
        "this is the most critical part of the process, if we don't get this right, the generated code will not work properly.\n",
        "\n",
        "please output a markdown file called shared_dependencies.md that lists all of the shared dependencies.\n",
        "\n",
        "the dependencies should be organized as:\n",
        "1. shared variables (globals, constants)\n",
        "2. shared functions (function signatures)\n",
        "3. shared classes (class names and key methods)\n",
        "4. shared imports (modules to import)\n",
        "5. shared DOM element ids (if web project)\n",
        "6. shared file paths/names\n",
        "\n",
        "be EXHAUSTIVE in your analysis. every file must be able to import or reference these shared items.\"\"\"\n",
        "\n",
        "        response = self.model.generate_content(\n",
        "            planning_prompt,\n",
        "            generation_config=self.generation_config\n",
        "        )\n",
        "        return response.text\n",
        "\n",
        "    def specify_file_paths(self, prompt: str, shared_deps: str) -> List[str]:\n",
        "        \"\"\"\n",
        "        Phase 2: Determine what files need to be created\n",
        "        \"\"\"\n",
        "        files_prompt = f\"\"\"You are an AI developer who is trying to write a program that will generate code for the user based on their intent.\n",
        "\n",
        "the program:\n",
        "{prompt}\n",
        "\n",
        "the shared dependencies:\n",
        "{shared_deps}\n",
        "\n",
        "Based on the program description and shared dependencies, return a JSON array of the filenames that should be written.\n",
        "\n",
        "Only return the JSON array, nothing else. The JSON should be an array of strings representing file paths.\n",
        "\n",
        "For example, for a simple web app you might return:\n",
        "[\"index.html\", \"styles.css\", \"script.js\"]\n",
        "\n",
        "For a Python project you might return:\n",
        "[\"main.py\", \"utils.py\", \"config.py\", \"requirements.txt\"]\n",
        "\n",
        "JSON array:\"\"\"\n",
        "\n",
        "        response = self.model.generate_content(\n",
        "            files_prompt,\n",
        "            generation_config=self.generation_config\n",
        "        )\n",
        "\n",
        "        try:\n",
        "            json_match = re.search(r'\\[.*?\\]', response.text, re.DOTALL)\n",
        "            if json_match:\n",
        "                files = json.loads(json_match.group())\n",
        "                return [f for f in files if isinstance(f, str)]\n",
        "            else:\n",
        "                lines = [line.strip() for line in response.text.split('\\n') if line.strip()]\n",
        "                files = []\n",
        "                for line in lines:\n",
        "                    if '.' in line and not line.startswith('#'):\n",
        "                        file = re.sub(r'[^\\w\\-_./]', '', line)\n",
        "                        if file:\n",
        "                            files.append(file)\n",
        "                return files[:10]\n",
        "        except Exception as e:\n",
        "            print(f\"Error parsing files: {e}\")\n",
        "            return [\"main.py\", \"README.md\"]\n",
        "\n",
        "    def generate_code_sync(self, prompt: str, shared_deps: str, filename: str) -> str:\n",
        "        \"\"\"\n",
        "        Phase 3: Generate code for individual files\n",
        "        \"\"\"\n",
        "        code_prompt = f\"\"\"You are an AI developer who is trying to write a program that will generate code for the user based on their intent.\n",
        "\n",
        "the program:\n",
        "{prompt}\n",
        "\n",
        "the shared dependencies:\n",
        "{shared_deps}\n",
        "\n",
        "Please write the file {filename}.\n",
        "\n",
        "Remember that your job is to write the code for {filename} ONLY. Do not write any other files.\n",
        "\n",
        "the code should be fully functional. meaning:\n",
        "- all imports should be correct\n",
        "- all variable references should be correct\n",
        "- all function calls should be correct\n",
        "- the code should be syntactically correct\n",
        "- the code should be logically correct\n",
        "\n",
        "Make sure to implement every part of the functionality described in the program description.\n",
        "\n",
        "DO NOT include ``` code fences in your response. Return only the raw code.\n",
        "\n",
        "Here is the code for {filename}:\"\"\"\n",
        "\n",
        "        response = self.model.generate_content(\n",
        "            code_prompt,\n",
        "            generation_config=self.generation_config\n",
        "        )\n",
        "\n",
        "        code = response.text\n",
        "        code = re.sub(r'^```[\\w]*\\n', '', code, flags=re.MULTILINE)\n",
        "        code = re.sub(r'\\n```$', '', code, flags=re.MULTILINE)\n",
        "\n",
        "        return code.strip()\n",
        "\n",
        "    def create_app(self, prompt: str, output_dir: str = \"/content/generated_app\") -> Dict:\n",
        "        \"\"\"\n",
        "        Main workflow: Transform a simple prompt into a complete application\n",
        "        \"\"\"\n",
        "        print(f\"🚀 TinyDev workflow starting...\")\n",
        "        print(f\"📝 Prompt: {prompt}\")\n",
        "\n",
        "        print(\"\\n📋 Step 1: Planning shared dependencies...\")\n",
        "        shared_deps = self.plan(prompt)\n",
        "        print(\"✅ Dependencies planned\")\n",
        "\n",
        "        print(\"\\n📁 Step 2: Determining file structure...\")\n",
        "        file_paths = self.specify_file_paths(prompt, shared_deps)\n",
        "        print(f\"📄 Files to generate: {file_paths}\")\n",
        "\n",
        "        Path(output_dir).mkdir(parents=True, exist_ok=True)\n",
        "\n",
        "        print(f\"\\n⚡ Step 3: Generating {len(file_paths)} files...\")\n",
        "        results = {\n",
        "            'prompt': prompt,\n",
        "            'shared_deps': shared_deps,\n",
        "            'files': {},\n",
        "            'output_dir': output_dir\n",
        "        }\n",
        "\n",
        "        with open(Path(output_dir) / \"shared_dependencies.md\", 'w') as f:\n",
        "            f.write(shared_deps)\n",
        "\n",
        "        for filename in file_paths:\n",
        "            print(f\"  🔧 Generating {filename}...\")\n",
        "            try:\n",
        "                code = self.generate_code_sync(prompt, shared_deps, filename)\n",
        "\n",
        "                file_path = Path(output_dir) / filename\n",
        "                file_path.parent.mkdir(parents=True, exist_ok=True)\n",
        "\n",
        "                with open(file_path, 'w', encoding='utf-8') as f:\n",
        "                    f.write(code)\n",
        "\n",
        "                results['files'][filename] = code\n",
        "                print(f\"  ✅ {filename} created ({len(code)} chars)\")\n",
        "\n",
        "            except Exception as e:\n",
        "                print(f\"  ❌ Error generating {filename}: {e}\")\n",
        "                results['files'][filename] = f\"# Error: {e}\"\n",
        "\n",
        "        readme = f\"\"\"# Generated by TinyDev (Gemini-Powered)\n",
        "\n",
        "## Original Prompt\n",
        "{prompt}\n",
        "\n",
        "## Generated Files\n",
        "{chr(10).join(f'- {f}' for f in file_paths)}\n",
        "\n",
        "## About TinyDev\n",
        "TinyDev is inspired by smol-ai/developer but uses free Gemini API.\n",
        "It follows the proven three-phase workflow: Plan → Files → Code\n",
        "\n",
        "## Usage\n",
        "Check individual files for specific usage instructions.\n",
        "\n",
        "Generated on: {os.popen('date').read().strip()}\n",
        "\"\"\"\n",
        "\n",
        "        with open(Path(output_dir) / \"README.md\", 'w') as f:\n",
        "            f.write(readme)\n",
        "\n",
        "        print(f\"\\n🎉 Complete! Generated {len(results['files'])} files in {output_dir}\")\n",
        "        return results"
      ],
      "metadata": {
        "id": "yh8xQCKcvtrp"
      },
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def demo_tinydev():\n",
        "    \"\"\"Demo the TinyDev code generator\"\"\"\n",
        "\n",
        "    api_key = \"Use Your API Key here\"\n",
        "\n",
        "    if api_key == \"YOUR_GEMINI_API_KEY_HERE\":\n",
        "        print(\"❌ Please set your Gemini API key!\")\n",
        "        print(\"Get one free at: https://makersuite.google.com/app/apikey\")\n",
        "        return None\n",
        "\n",
        "    tiny_dev = TinyDev(api_key)\n",
        "\n",
        "    demo_prompts = [\n",
        "        \"a simple HTML/JS/CSS tic tac toe game\",\n",
        "        \"a Python web scraper that gets the latest news from multiple sources\",\n",
        "        \"a responsive landing page for a local coffee shop with contact form\",\n",
        "        \"a Flask REST API for managing a todo list\",\n",
        "        \"a JavaScript calculator with a modern UI\"\n",
        "    ]\n",
        "\n",
        "    print(\"🤖 TinyDev - AI Code Generator\")\n",
        "    print(\"=\" * 50)\n",
        "    print(\"Inspired by smol-ai/developer, powered by Gemini API\")\n",
        "    print(f\"Available demo projects:\")\n",
        "\n",
        "    for i, prompt in enumerate(demo_prompts, 1):\n",
        "        print(f\"{i}. {prompt}\")\n",
        "\n",
        "    demo_prompt = demo_prompts[0]\n",
        "    print(f\"\\n🎯 Running demo: {demo_prompt}\")\n",
        "\n",
        "    try:\n",
        "        results = tiny_dev.create_app(demo_prompt)\n",
        "\n",
        "        print(f\"\\n📊 Results Summary:\")\n",
        "        print(f\"  📝 Prompt: {results['prompt']}\")\n",
        "        print(f\"  📁 Output: {results['output_dir']}\")\n",
        "        print(f\"  📄 Files: {len(results['files'])}\")\n",
        "\n",
        "        print(f\"\\n📋 Generated Files:\")\n",
        "        for filename in results['files'].keys():\n",
        "            print(f\"  - {filename}\")\n",
        "\n",
        "        if results['files']:\n",
        "            preview_file = list(results['files'].keys())[0]\n",
        "            preview_code = results['files'][preview_file]\n",
        "            print(f\"\\n👁️  Preview of {preview_file}:\")\n",
        "            print(\"-\" * 40)\n",
        "            print(preview_code[:400] + \"...\" if len(preview_code) > 400 else preview_code)\n",
        "            print(\"-\" * 40)\n",
        "\n",
        "        print(f\"\\n💡 This uses the same proven workflow as smol-ai/developer!\")\n",
        "        print(f\"📂 Check {results['output_dir']} for all generated files\")\n",
        "\n",
        "        return results\n",
        "\n",
        "    except Exception as e:\n",
        "        print(f\"❌ Demo failed: {e}\")\n",
        "        return None"
      ],
      "metadata": {
        "id": "COKoPmfgv20r"
      },
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def interactive_tinydev():\n",
        "    \"\"\"Interactive version where you can try your own prompts\"\"\"\n",
        "    api_key = input(\"🔑 Enter your Gemini API key: \").strip()\n",
        "\n",
        "    if not api_key:\n",
        "        print(\"❌ API key required!\")\n",
        "        return\n",
        "\n",
        "    tiny_dev = TinyDev(api_key)\n",
        "\n",
        "    print(\"\\n🎮 Interactive TinyDev Mode\")\n",
        "    print(\"Type your app ideas and watch them come to life!\")\n",
        "\n",
        "    while True:\n",
        "        prompt = input(\"\\n💭 Describe your app (or 'quit'): \").strip()\n",
        "\n",
        "        if prompt.lower() in ['quit', 'exit', 'q']:\n",
        "            print(\"👋 Goodbye!\")\n",
        "            break\n",
        "\n",
        "        if prompt:\n",
        "            try:\n",
        "                results = tiny_dev.create_app(prompt, f\"/content/app_{hash(prompt) % 10000}\")\n",
        "                print(f\"✅ Success! Check {results['output_dir']}\")\n",
        "            except Exception as e:\n",
        "                print(f\"❌ Error: {e}\")\n",
        "\n",
        "print(\"🎬 TinyDev - AI Code Generator Ready!\")\n",
        "print(\"Inspired by smol-ai/developer, powered by free Gemini API\")\n",
        "print(\"\\nTo run demo: demo_tinydev()\")\n",
        "print(\"To try interactive mode: interactive_tinydev()\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "p81o-RHqv67h",
        "outputId": "e593ca06-cca6-404a-dc08-784cd6601a5b"
      },
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "🎬 TinyDev - AI Code Generator Ready!\n",
            "Inspired by smol-ai/developer, powered by free Gemini API\n",
            "\n",
            "To run demo: demo_tinydev()\n",
            "To try interactive mode: interactive_tinydev()\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "demo_tinydev()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "pBsGeTgAoVK_",
        "outputId": "667e519b-04a5-4798-ba18-b6f9d6cd1a82"
      },
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "🤖 TinyDev - AI Code Generator\n",
            "==================================================\n",
            "Inspired by smol-ai/developer, powered by Gemini API\n",
            "Available demo projects:\n",
            "1. a simple HTML/JS/CSS tic tac toe game\n",
            "2. a Python web scraper that gets the latest news from multiple sources\n",
            "3. a responsive landing page for a local coffee shop with contact form\n",
            "4. a Flask REST API for managing a todo list\n",
            "5. a JavaScript calculator with a modern UI\n",
            "\n",
            "🎯 Running demo: a simple HTML/JS/CSS tic tac toe game\n",
            "🚀 TinyDev workflow starting...\n",
            "📝 Prompt: a simple HTML/JS/CSS tic tac toe game\n",
            "\n",
            "📋 Step 1: Planning shared dependencies...\n",
            "✅ Dependencies planned\n",
            "\n",
            "📁 Step 2: Determining file structure...\n",
            "📄 Files to generate: ['index.html', 'style.css', 'script.js']\n",
            "\n",
            "⚡ Step 3: Generating 3 files...\n",
            "  🔧 Generating index.html...\n",
            "  ✅ index.html created (312 chars)\n",
            "  🔧 Generating style.css...\n",
            "  ✅ style.css created (726 chars)\n",
            "  🔧 Generating script.js...\n",
            "  ✅ script.js created (2501 chars)\n",
            "\n",
            "🎉 Complete! Generated 3 files in /content/generated_app\n",
            "\n",
            "📊 Results Summary:\n",
            "  📝 Prompt: a simple HTML/JS/CSS tic tac toe game\n",
            "  📁 Output: /content/generated_app\n",
            "  📄 Files: 3\n",
            "\n",
            "📋 Generated Files:\n",
            "  - index.html\n",
            "  - style.css\n",
            "  - script.js\n",
            "\n",
            "👁️  Preview of index.html:\n",
            "----------------------------------------\n",
            "<!DOCTYPE html>\n",
            "<html>\n",
            "<head>\n",
            "<title>Tic-Tac-Toe</title>\n",
            "<link rel=\"stylesheet\" href=\"style.css\">\n",
            "</head>\n",
            "<body>\n",
            "  <h1>Tic-Tac-Toe</h1>\n",
            "  <div id=\"game-status\">X's turn</div>\n",
            "  <table id=\"game-board\"></table>\n",
            "  <button onclick=\"resetGame()\">Reset Game</button>\n",
            "  <script src=\"script.js\"></script>\n",
            "</body>\n",
            "</html>\n",
            "----------------------------------------\n",
            "\n",
            "💡 This uses the same proven workflow as smol-ai/developer!\n",
            "📂 Check /content/generated_app for all generated files\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'prompt': 'a simple HTML/JS/CSS tic tac toe game',\n",
              " 'shared_deps': '```markdown\\n# shared_dependencies.md\\n\\nThis document outlines the shared dependencies for a Tic-Tac-Toe game implemented using HTML, CSS, and JavaScript, generated by a Python script.  Consistency in these shared elements is crucial for the generated code\\'s functionality.\\n\\n\\n## 1. Shared Variables (Globals, Constants)\\n\\n* `BOARD_SIZE`: Integer representing the size of the Tic-Tac-Toe board (default: 3).  This determines the number of rows and columns.\\n* `PLAYER_X`: String representing Player X (default: \"X\").\\n* `PLAYER_O`: String representing Player O (default: \"O\").\\n* `EMPTY_CELL`: String representing an empty cell on the board (default: \"\").\\n* `GAME_STATE`:  String representing the current game state. Possible values:  \"in progress\", \"X wins\", \"O wins\", \"draw\".  Initialized to \"in progress\".\\n* `current_player`: String representing the current player\\'s turn (initialized to `PLAYER_X`).\\n\\n\\n## 2. Shared Functions (Function Signatures)\\n\\n* `initialize_board()`: Initializes the game board to an empty state.  Returns a 2D array representing the board.\\n* `make_move(row, col, player)`: Makes a move on the board. Takes row, column, and player as input. Returns `True` if the move is valid, `False` otherwise.  Updates `GAME_STATE` and `current_player`.\\n* `check_win(board, player)`: Checks if the given player has won the game. Returns `True` if the player has won, `False` otherwise.\\n* `check_draw(board)`: Checks if the game is a draw. Returns `True` if it\\'s a draw, `False` otherwise.\\n* `update_board_display()`: Updates the visual representation of the board on the webpage (HTML). This function will interact with DOM elements.\\n* `handle_cell_click(row, col)`: Event handler for cell clicks. Calls `make_move` and updates the display.\\n* `reset_game()`: Resets the game to its initial state.\\n\\n\\n## 3. Shared Classes (Class Names and Key Methods)\\n\\n* (Optional)  `TicTacToeGame`: A class to encapsulate the game logic.  Methods would include `__init__`, `make_move`, `check_win`, `check_draw`, `reset_game`, `get_board`.  This is optional, but recommended for better organization.\\n\\n\\n## 4. Shared Imports (Modules to Import)\\n\\n* (JavaScript)  No specific modules are strictly required, but using a module bundler (like Webpack or Parcel) might be beneficial for larger projects.\\n\\n\\n## 5. Shared DOM Element IDs\\n\\n* `game-board`: ID of the HTML element representing the game board (a table or div).\\n* `game-status`: ID of the HTML element displaying the game status (e.g., \"X\\'s turn\", \"X wins\").  This could be a `<p>` or `<span>` tag.\\n* Individual cell IDs within the `game-board` (e.g., `cell-0-0`, `cell-1-2`, etc.).  A consistent naming scheme is crucial.  Consider using a function to generate these IDs dynamically based on row and column indices.\\n\\n\\n## 6. Shared File Paths/Names\\n\\n* `index.html`: Main HTML file.\\n* `style.css`: CSS file for styling.\\n* `script.js`: JavaScript file containing game logic.  (Or potentially multiple JS files if using modules).\\n\\n\\n**Note:** The Python script will generate these files, ensuring consistency in variable names, function calls, and DOM element IDs.  The Python script should also handle the dynamic generation of cell IDs within the `index.html` file.\\n```\\n',\n",
              " 'files': {'index.html': '<!DOCTYPE html>\\n<html>\\n<head>\\n<title>Tic-Tac-Toe</title>\\n<link rel=\"stylesheet\" href=\"style.css\">\\n</head>\\n<body>\\n  <h1>Tic-Tac-Toe</h1>\\n  <div id=\"game-status\">X\\'s turn</div>\\n  <table id=\"game-board\"></table>\\n  <button onclick=\"resetGame()\">Reset Game</button>\\n  <script src=\"script.js\"></script>\\n</body>\\n</html>',\n",
              "  'style.css': 'body {\\n  font-family: sans-serif;\\n  display: flex;\\n  justify-content: center;\\n  align-items: center;\\n  min-height: 100vh;\\n  background-color: #f0f0f0;\\n}\\n\\n#game-board {\\n  display: grid;\\n  grid-template-columns: repeat(3, 100px);\\n  grid-template-rows: repeat(3, 100px);\\n  grid-gap: 5px;\\n  border-collapse: collapse;\\n  border: 2px solid #333;\\n}\\n\\n.cell {\\n  width: 100px;\\n  height: 100px;\\n  background-color: #fff;\\n  border: 1px solid #ccc;\\n  display: flex;\\n  justify-content: center;\\n  align-items: center;\\n  font-size: 60px;\\n  cursor: pointer;\\n}\\n\\n.cell:hover {\\n  background-color: #e0e0e0;\\n}\\n\\n#game-status {\\n  margin-top: 20px;\\n  font-size: 20px;\\n  text-align: center;\\n}\\n\\n.player-x {\\n  color: blue;\\n}\\n\\n.player-o {\\n  color: red;\\n}',\n",
              "  'script.js': 'const BOARD_SIZE = 3;\\nconst PLAYER_X = \"X\";\\nconst PLAYER_O = \"O\";\\nconst EMPTY_CELL = \"\";\\nlet GAME_STATE = \"in progress\";\\nlet current_player = PLAYER_X;\\nlet board = [];\\n\\nfunction initialize_board() {\\n  board = Array.from(Array(BOARD_SIZE), () => new Array(BOARD_SIZE).fill(EMPTY_CELL));\\n  update_board_display();\\n}\\n\\nfunction make_move(row, col, player) {\\n  if (board[row][col] === EMPTY_CELL && GAME_STATE === \"in progress\") {\\n    board[row][col] = player;\\n    update_board_display();\\n    if (check_win(board, player)) {\\n      GAME_STATE = player + \" wins\";\\n      update_game_status();\\n    } else if (check_draw(board)) {\\n      GAME_STATE = \"draw\";\\n      update_game_status();\\n    } else {\\n      current_player = (player === PLAYER_X) ? PLAYER_O : PLAYER_X;\\n      update_game_status();\\n    }\\n    return true;\\n  }\\n  return false;\\n}\\n\\nfunction check_win(board, player) {\\n  // Check rows, columns, and diagonals\\n  for (let i = 0; i < BOARD_SIZE; i++) {\\n    if (board[i].every(cell => cell === player) ||\\n        board.map(row => row[i]).every(cell => cell === player)) {\\n      return true;\\n    }\\n  }\\n  if ((board[0][0] === player && board[1][1] === player && board[2][2] === player) ||\\n      (board[0][2] === player && board[1][1] === player && board[2][0] === player)) {\\n    return true;\\n  }\\n  return false;\\n}\\n\\nfunction check_draw(board) {\\n  return board.every(row => row.every(cell => cell !== EMPTY_CELL));\\n}\\n\\nfunction update_board_display() {\\n  const gameBoard = document.getElementById(\"game-board\");\\n  gameBoard.innerHTML = \"\"; // Clear the board\\n  for (let i = 0; i < BOARD_SIZE; i++) {\\n    for (let j = 0; j < BOARD_SIZE; j++) {\\n      const cell = document.createElement(\"div\");\\n      cell.id = `cell-${i}-${j}`;\\n      cell.classList.add(\"cell\");\\n      cell.textContent = board[i][j];\\n      cell.addEventListener(\"click\", () => handle_cell_click(i, j));\\n      gameBoard.appendChild(cell);\\n    }\\n  }\\n}\\n\\nfunction update_game_status() {\\n  const gameStatus = document.getElementById(\"game-status\");\\n  gameStatus.textContent = GAME_STATE === \"in progress\" ? `${current_player}\\'s turn` : GAME_STATE;\\n}\\n\\nfunction handle_cell_click(row, col) {\\n  make_move(row, col, current_player);\\n}\\n\\nfunction reset_game() {\\n  GAME_STATE = \"in progress\";\\n  current_player = PLAYER_X;\\n  initialize_board();\\n  update_game_status();\\n}\\n\\nwindow.onload = () => {\\n  initialize_board();\\n  update_game_status();\\n  const resetButton = document.getElementById(\"reset-button\");\\n  resetButton.addEventListener(\"click\", reset_game);\\n};'},\n",
              " 'output_dir': '/content/generated_app'}"
            ]
          },
          "metadata": {},
          "execution_count": 13
        }
      ]
    }
  ]
}